<?php
	namespace Qzn\Controller;
	require_once('./Model/fileUploadHandler.php');
	require_once('./View/fileUploadView.php');
	
	class FileUploadController {
		
		/**
		 * @param boolean $login
		 * @return string HTML
		 */
		public function DoControll(\Qzn\Model\Database $db, \Qzn\View\LoginView $lw, \Qzn\Model\LoginHandler $lh) {
			$fuv = new \Qzn\View\FileUploadView();
			$fuh = new \Qzn\Model\FileUploadHandler($db);
			$html = "";
			
			if ($fuv->TriedToUpload()) {
				$errorCode = $this->FileUpload($fuv, $lw, $fuh);
				$html .= $lw->ErrorHandler($errorCode);
			}
			
			if ($lh->IsLoggedIn()) {
				$html .= $fuv->DoFileUploadBox();
			}
			
			return $html;
		}
		
		/**
		 * Call UploadFile(GetFile)
		 * @return string HTML
		 */
		public function FileUpload(\Qzn\View\FileUploadView $fuv, \Qzn\View\LoginView $lw, \Qzn\Model\FileUploadHandler $fuh) {
			
			return $fuh->UploadFile($fuv->GetFile(), $lw);
		}
	}
?>